package com.ganzi.manager.controller;

import com.ganzi.manager.activiti.request.VacationRequest;
import com.ganzi.manager.activiti.service.imp.VacationService;
import com.ganzi.manager.model.User;
import com.ganzi.manager.shiro.redis.OtherCache.UserCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 流程管理
 * */
@RestController
@RequestMapping("/vac")
public class VacationController {

    @Resource
    private VacationService vacationService;
    @Autowired
    UserCache userCache;

    /**
     * 获取表单页面
     * */
    @GetMapping("/getVac")
    public Object getStartPage(@RequestParam String processDefinitionId) {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.getStartPage(userId, processDefinitionId);
    }
    /**
     * 提交审批
     * */
    @PostMapping("/startVac")
    public Object startVac(HttpServletRequest request) {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.startVac(userId, request);
    }


    /**
     * 自定义审批人（-----测试中  暂时没有使用------）
     * */
    @PostMapping("/startVacByAssignee")
    public Object startVacByAssignee(@RequestBody VacationRequest vac) {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.startVacByAssignee(userId, vac);
    }


    /**
     * 我正在申请的
     * */
    @GetMapping("/myVac")
    public Object myVac() {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.myVac(userId);
    }


    /**
     * 等待我审批的
     * */
    @GetMapping("/myAudit")
    public Object myAudit() {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.myAudit(userId);
    }
    /**
     * 进入审批详情页面
     * */
    @GetMapping("/AuditInformation")
    public Object AuditInformation(HttpServletRequest request) {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        String taskId = request.getParameter("taskId");
        return vacationService.AuditInformation(userId, taskId);
    }


     /**提交审核操作
     * */
    @PostMapping("/passAudit")
    public Object passAudit(HttpServletRequest request) {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.passAudit(userId,request);
    }


    /**
     * 我申请完成的
     * */
    @GetMapping("/myVacRecord")
    public Object myVacRecord() {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.myVacRecord(userId);
    }
    /**
     * 我申请完成的详情页面
     * */
    @GetMapping("/initiateComplete")
    public Object AuditDetil(HttpServletRequest request) {
        String processId = request.getParameter("processId");
        return vacationService.initiateComplete(processId);
    }


    /**
     * 我审批完成的
     * */
    @GetMapping("/myAuditRecord")
    public Object myAuditRecord() {
        User user = userCache.getUserByPrincipal();
        String userId = String.valueOf(user.getId());
        return vacationService.myAuditRecord(userId);
    }


    /**
     * 显示所有发布的流程（可以设置显示最新版本）
     */
    @GetMapping("/allProcess")
    public Object allProcess() {
        return vacationService.getProcess();
    }
}
